from celery_tasks.main import app
from meiduo_mall.libs.yuntongxun.sms import CCP
import logging


@app.task()
def sms(mobile, sms_code):
    print(sms_code)
    logger = logging.getLogger("django")
    try:
        ccp = CCP()
        result = ccp.send_template_sms(mobile, [sms_code, '5'], 1)
        print(sms_code.decode())
        print('ss%s' %sms_code)
    except Exception as e:
        # 这些返回的信息 都会在终端里面显示
        # celery -A celery_tasks.main worker -l info
        logger.error("发送验证码短信[异常][ mobile: %s, message: %s ]" % (mobile, e))
    else:
        if result == 0:
            logger.info("发送验证码短信[正常][ mobile: %s ]" % mobile)
        else:
            logger.warning("发送验证码短信[失败][ mobile: %s ]" % mobile)